package com.jydd.singlekotlinmvvm.comm.feature.main

import com.jydd.singlekotlinmvvm.comm.base.BaseLiveData
import com.jydd.singlekotlinmvvm.comm.base.BaseViewModel
import com.jydd.singlekotlinmvvm.comm.client.apis.GitApi
import com.jydd.singlekotlinmvvm.comm.model.response.RepoInfo
import com.jydd.singlekotlinmvvm.comm.repo.UserDataSource

/**
 * created by 韦敏敏
 * on 2020/1/22
 */
class RepoViewModel(
    private val userRepo : UserDataSource,
    private val gitApi : GitApi
) : BaseViewModel() {
    private val _reposResult = BaseLiveData<List<RepoInfo>>()
    val repoResult : BaseLiveData<List<RepoInfo>>
        get() = _reposResult
    fun fetchRepos(module: String){
        request {
            userRepo.currUser()?.let {
                val result = gitApi.repos(it.nickName, module, 1)
                _reposResult.update(result)
            }
        }
    }
}